// 配置路由信息
import Vue from 'vue'
import Router from 'vue-router'

const Home = () => import("../views/home/Home")
const HomeNews = () => import("../views/home/HomeNews")
const HomeMessage = () => import("../views/home/HomeMessage")
const About = () => import("../views/about/About")
const User = () => import("../views/user/User")
const Profile = () => import("../views/profile/Profile")

// 通过 Vue.use 安装Router插件
Vue.use(Router)

// 配置路由和组件之间的关系
const routes = [
	{path: "", redirect: "/home"},
	{
		path: "/home",
		meta: {
			title: "首页"
		},
		name: "Home",
		component: Home,
		children: [
			{path: '', redirect: "news"},
			{path: 'news', component: HomeNews},
			{path: 'message', component: HomeMessage}]
	},
	{
		path: "/about",
		meta: {
			title: "关于"
		},
		name: "About",
		component: About},
	{
		path: "/user/:userId",
		meta: {
			title: "用户"
		},	name: "User",
		component: User
	},
	{
		path: "/profile",
		meta: {
			title: "档案"
		},	name: "Profile",
		component: Profile
	}
]

const router = new Router({
	routes,
	mode: 'history'
})

router.beforeEach(function (to, from, next) {
	document.title = to.meta.title
	next()
})

export default router




